package com.godpaper.the2tigers.busniess.managers
{
	import com.godpaper.the2tigers.busniess.AI.IAIBehavior;
	import com.godpaper.the2tigers.busniess.AI.RandomWalkAI;
	import com.godpaper.the2tigers.busniess.factorys.ButtonFactory;
	import com.godpaper.the2tigers.model.BoardModel;
	import com.godpaper.the2tigers.model.PlayerModel;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;

	public class PlayerManager
	{
		private static var gameAI:IAIBehavior;
		public function PlayerManager()
		{
		}
		
		public static function computerWin():void
		{
			ProgressBarManager.getInstance().removeProgressBar();
			mx.controls.Alert.show("COMPUTER WIN!");
		}
		public static function humanWin():void
		{
			ProgressBarManager.getInstance().removeProgressBar();
			mx.controls.Alert.show("HUMAN WIN!");
		}
		
		public static function isComputerTurnNow():void
		{
			ProgressBarManager.getInstance().showProgressBar();
			
			PlayerModel.getInstance().gameTurnStatus = !PlayerModel.getInstance().gameTurnStatus;
			
			//todo:
			gameAI = new RandomWalkAI(BoardModel.getInstance().gamePosition);
		}
		public static function isHumanTurnNow():void
		{
			ProgressBarManager.getInstance().removeProgressBar();
			
			PlayerModel.getInstance().gameTurnStatus = !PlayerModel.getInstance().gameTurnStatus;
			//todo:
		}
		//whether game ended or some pieces beKilled.
		public static function analysisGamePhases(reds:ArrayCollection,blues:ArrayCollection):Boolean
		{
			trace("#####################analysisGame begin##########################");
			if(blues.length<=ButtonFactory.MAX_PIECE_NUM_DOGS-6)
			{
				computerWin();
			}else if(reds.length==0)
			{
				humanWin();
			}
			trace("#####################analysisGame end##########################");
			return (reds.length==0 || blues.length<=ButtonFactory.MAX_PIECE_NUM_DOGS-6);
		}
		
	}
}